package com.qimo.zzy.controller;

import com.qimo.zzy.service.AddressService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@CrossOrigin//跨域
@RestController//遵循RestFul
@RequestMapping("/qimo/Address/")
public class AddressController {

    @Resource
    AddressService addressService;

    /**
     * 获取当前用户的所有地址
     *
     * @param uid
     * @return
     */
    @GetMapping("getAddressList")
    private String getAddressList(@RequestParam("uid") int uid) {
        System.out.println(addressService.getAddressList(uid));
        return addressService.getAddressList(uid);
    }

    /**
     * 删除用户地址
     *
     * @param addressId
     * @return
     */
    @PostMapping("delAddress")
    private String delAddress(
            @RequestParam("addressId") int addressId
    ) {
        return addressService.delAddress(addressId);
    }

    /**
     * 修改用户地址
     *
     * @param addressId
     * @param receiver
     * @param province
     * @param city
     * @param county
     * @param address
     * @param areaCode
     * @param cellPhone
     * @param fixedPhone
     * @param postCode
     * @param tag
     * @param isDefault
     * @return
     */
    @PostMapping("chanceAddress")
    private String chanceAddress(
            @RequestParam("addressId") int addressId,
            @RequestParam("receiver") String receiver,
            @RequestParam("province") String province,
            @RequestParam("city") String city,
            @RequestParam("county") String county,
            @RequestParam("address") String address,
            @RequestParam("areaCode") String areaCode,
            @RequestParam("cellPhone") String cellPhone,
            @RequestParam("fixedPhone") String fixedPhone,
            @RequestParam("postCode") String postCode,
            @RequestParam("tag") String tag,
            @RequestParam("isDefault") int isDefault
    ) {
        return addressService.chanceAddress(addressId, receiver, province, city, county, address, areaCode, cellPhone, fixedPhone, postCode, tag, isDefault);
    }

    /**
     * 新增用户地址
     *
     * @param uid
     * @param receiver
     * @param province
     * @param city
     * @param county
     * @param address
     * @param areaCode
     * @param cellPhone
     * @param fixedPhone
     * @param postCode
     * @param tag
     * @param isDefault
     * @return
     */
    @PostMapping("addAddress")
    private String addAddress(
            @RequestParam("uid") int uid,
            @RequestParam("receiver") String receiver,
            @RequestParam("province") String province,
            @RequestParam("city") String city,
            @RequestParam("county") String county,
            @RequestParam("address") String address,
            @RequestParam("areaCode") String areaCode,
            @RequestParam("cellPhone") String cellPhone,
            @RequestParam("fixedPhone") String fixedPhone,
            @RequestParam("postCode") String postCode,
            @RequestParam("tag") String tag,
            @RequestParam("isDefault") int isDefault
    ) {
        return addressService.addAddress(uid, receiver, province, city, county, address, areaCode, cellPhone, fixedPhone, postCode, tag, isDefault);
    }

}